﻿<Window x:Class="CncConvProg.View.Dialog.ArticleMaterialeView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ab="clr-namespace:CncConvProg.View.AttachedProperty" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" 
        Title="Material Detail" 
        WindowStyle="ToolWindow"
        WindowState="Normal"
        Height="Auto"
        WindowStartupLocation="CenterScreen"
        >
    <Window.Resources>
        <Style x:Key="ImageStyle">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=Materiale.GruppoMateriale}" Value="0">
                    <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_p.png"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Path= Materiale.GruppoMateriale}" Value="1">
                    <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_m.png"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Path=Materiale.GruppoMateriale}" Value="2">
                    <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_k.png"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Path= Materiale.GruppoMateriale}" Value="3">
                    <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_n.png"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Path=Materiale.GruppoMateriale}" Value="4">
                    <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_h.png"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Path=Materiale.GruppoMateriale}" Value="5">
                    <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_s.png"/>
                </DataTrigger>

            </Style.Triggers>
        </Style>
        <DataTemplate x:Key="PrezzoMaterialCbTemplate">
            <StackPanel Orientation="Horizontal">
                <Image Width="22" Height="22" Style="{StaticResource ResourceKey=ImageStyle}" />
                <TextBlock Text="{Binding Path=FormatedPrezzoDescription}"/>
            </StackPanel>
        </DataTemplate>
        <ControlTemplate x:Key="PrezzoMaterialComboBoxTemplate" TargetType="{x:Type ComboBox}">
            <Grid x:Name="MainGrid" SnapsToDevicePixels="True">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Width="0"/>
                </Grid.ColumnDefinitions>
                <Popup x:Name="PART_Popup" AllowsTransparency="True" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
                    <Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=MainGrid}">
                        <Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
                            <ListView SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ItemsSource="{TemplateBinding ItemsSource}"
                                                              SelectedItem="{Binding SelectedItem, RelativeSource={RelativeSource TemplatedParent}}" >
                                <ListView.View>
                                    <GridView>
                                        <GridViewColumn Header="">
                                            <GridViewColumn.CellTemplate>
                                                <DataTemplate>
                                                    <Image Width="22" Height="22" >
                                                        <Image.Style>
                                                            <Style>
                                                                <Style.Triggers>
                                                                    <DataTrigger Binding="{Binding Path=Materiale.GruppoMateriale}" Value="0">
                                                                        <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_p.png"/>
                                                                    </DataTrigger>

                                                                    <DataTrigger Binding="{Binding Path= Materiale.GruppoMateriale}" Value="1">
                                                                        <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_m.png"/>
                                                                    </DataTrigger>

                                                                    <DataTrigger Binding="{Binding Path=Materiale.GruppoMateriale}" Value="2">
                                                                        <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_k.png"/>
                                                                    </DataTrigger>

                                                                    <DataTrigger Binding="{Binding Path= Materiale.GruppoMateriale}" Value="3">
                                                                        <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_n.png"/>
                                                                    </DataTrigger>

                                                                    <DataTrigger Binding="{Binding Path=Materiale.GruppoMateriale}" Value="4">
                                                                        <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_h.png"/>
                                                                    </DataTrigger>

                                                                    <DataTrigger Binding="{Binding Path=Materiale.GruppoMateriale}" Value="5">
                                                                        <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_s.png"/>
                                                                    </DataTrigger>

                                                                </Style.Triggers>
                                                            </Style>
                                                        </Image.Style>
                                                    </Image>
                                                </DataTemplate>
                                            </GridViewColumn.CellTemplate>
                                        </GridViewColumn>
                                        <GridViewColumn Header="Materiale" DisplayMemberBinding="{Binding Path=Materiale.Descrizione}" Width="150"/>
                                        <GridViewColumn Header="Peso Specifico" DisplayMemberBinding="{Binding Path=Materiale.PesoSpecifico, StringFormat=F2}" Width="60"/>
                                        <GridViewColumn Header="Descrizione" DisplayMemberBinding="{Binding Path=Descrizione}" Width="150"/>
                                        <GridViewColumn Header="€/Kg" DisplayMemberBinding="{Binding Path=Prezzo}" Width="60"/>
                                    </GridView>
                                </ListView.View>
                            </ListView>
                        </Border>
                    </Microsoft_Windows_Themes:SystemDropShadowChrome>
                </Popup>
                <ToggleButton BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
                    <ToggleButton.Style>
                        <Style TargetType="{x:Type ToggleButton}">
                            <Setter Property="OverridesDefaultStyle" Value="True"/>
                            <Setter Property="IsTabStop" Value="False"/>
                            <Setter Property="Focusable" Value="False"/>
                            <Setter Property="ClickMode" Value="Press"/>
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ToggleButton}">
                                        <Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="True">
                                            <Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
                                                <Path x:Name="Arrow" Data="M0,0L3.5,4 7,0z" Fill="Black" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/>
                                            </Grid>
                                        </Microsoft_Windows_Themes:ButtonChrome>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsChecked" Value="True">
                                                <Setter Property="RenderPressed" TargetName="Chrome" Value="True"/>
                                            </Trigger>
                                            <Trigger Property="IsEnabled" Value="False">
                                                <Setter Property="Fill" TargetName="Arrow" Value="#FFAFAFAF"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ToggleButton.Style>
                </ToggleButton>
                <ContentPresenter ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="False" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="True">
                    <Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
                    <Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
                </Trigger>
                <Trigger Property="HasItems" Value="False">
                    <Setter Property="Height" TargetName="DropDownBorder" Value="95"/>
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    <Setter Property="Background" Value="#FFF4F4F4"/>
                </Trigger>
                <Trigger Property="IsGrouping" Value="True">
                    <Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>

        <Style TargetType="{x:Type ListViewItem}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>

    </Window.Resources>
    <Grid >
        <Grid.RowDefinitions>
            <RowDefinition Height=".5*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Border x:Name="Colonna_SX" Padding="4" Grid.RowSpan="1">
            <StackPanel>
                <Button Content="Aggiungi Dettaglio" Command="{Binding Path=NewMaterialDetailCmd}" Width="200" HorizontalAlignment="Left" Height="30" Margin="5"/>
                <ListView ItemsSource="{Binding  Path=DettagliMateriale}" SelectionMode="Single" SelectedItem="{Binding Path=DettaglioSelezionato}" Margin="5" >
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="Materiale" Width="300">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <ComboBox x:Name="cbMaterial" 
            								ItemsSource="{Binding Path=DataContext.PrezziMaterialiLookUp, RelativeSource={RelativeSource AncestorType={x:Type Window}, Mode=FindAncestor}}"
            								SelectedItem="{Binding Path=PrezzoMateriale}"
                                            ItemTemplate="{StaticResource ResourceKey=PrezzoMaterialCbTemplate}"
            								Template="{StaticResource ResourceKey=PrezzoMaterialComboBoxTemplate}"
            								IsDropDownOpen="{Binding Path=IsEditingMaterial}"
                                        />
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="Sezione" Width="150">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <ComboBox x:Name="cbMaterial" 
            								ItemsSource="{Binding Path=DataContext.SezioniLookup, RelativeSource={RelativeSource AncestorType={x:Type Window}, Mode=FindAncestor}}"
            								SelectedValue="{Binding Path=Sezione}"
            								SelectedValuePath="Key" 
                                            >
                                            <ComboBox.ItemTemplate>
                                                <DataTemplate>
                                                    <TextBlock Text="{Binding Value}"/>
                                                </DataTemplate>
                                            </ComboBox.ItemTemplate>
                                        </ComboBox>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>

                            <GridViewColumn Header="Misure" Width="170">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <ContentControl Content="{Binding}">
                                            <ContentControl.Resources>
                                                <Style TargetType="{x:Type TextBlock}">
                                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                                    <Setter Property="Margin" Value="5,0,0,0"/>
                                                </Style>
                                                <Style TargetType="{x:Type TextBox}">
                                                    <Setter Property="VerticalAlignment" Value="Center"/>
                                                    <Setter Property="Margin" Value="5,0,0,0"/>
                                                </Style>

                                                <DataTemplate x:Key="SezioneCerchio">
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="D1 : " />
                                                        <TextBox Text="{Binding DiametroEsterno}" ab:AttachedProperties.AutoSelectText="True"  />
                                                    </StackPanel>
                                                </DataTemplate>

                                                <DataTemplate x:Key="SezionePiatto">
                                                    <StackPanel Orientation="Horizontal" >
                                                        <TextBlock Text="L1 : " />
                                                        <TextBox Text="{Binding LatoMaggiore}" ab:AttachedProperties.AutoSelectText="True" />
                                                        <TextBlock Text="L2 :"/>
                                                        <TextBox Text="{Binding LatoMinore}"   ab:AttachedProperties.AutoSelectText="True" />
                                                    </StackPanel>
                                                </DataTemplate>

                                                <DataTemplate x:Key="SezioneTubo">
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="D.est : "/>
                                                        <TextBox Text="{Binding DiametroEsterno}" ab:AttachedProperties.AutoSelectText="True" />
                                                        <TextBlock Text="D.int : "/>
                                                        <TextBox Text="{Binding DiametroInterno}" ab:AttachedProperties.AutoSelectText="True" />
                                                    </StackPanel>
                                                </DataTemplate>

                                                <DataTemplate x:Key="SezioneQuadro">
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="Lato: "/>
                                                        <TextBox Text="{Binding LatoMaggiore}" ab:AttachedProperties.AutoSelectText="True" />
                                                    </StackPanel>
                                                </DataTemplate>

                                                <DataTemplate x:Key="SezioneEsagono">
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="Chiave"/>
                                                        <TextBox Text="{Binding ChiaveEsagono}" ab:AttachedProperties.AutoSelectText="True" />
                                                    </StackPanel>
                                                </DataTemplate>

                                            </ContentControl.Resources>
                                            <ContentControl.Style>
                                                <Style>
                                                    <Style.Triggers>

                                                        <DataTrigger Binding="{Binding Sezione}" Value="0">
                                                            <Setter Property="ContentControl.ContentTemplate" Value="{StaticResource ResourceKey=SezioneCerchio}"/>
                                                        </DataTrigger>

                                                        <DataTrigger Binding="{Binding Sezione}" Value="1">
                                                            <Setter Property="ContentControl.ContentTemplate" Value="{StaticResource ResourceKey=SezionePiatto}"/>
                                                        </DataTrigger>

                                                        <DataTrigger Binding="{Binding Sezione}" Value="2">
                                                            <Setter Property="ContentControl.ContentTemplate" Value="{StaticResource ResourceKey=SezioneTubo}"/>
                                                        </DataTrigger>

                                                        <DataTrigger Binding="{Binding Sezione}" Value="3">
                                                            <Setter Property="ContentControl.ContentTemplate" Value="{StaticResource ResourceKey=SezioneQuadro}"/>
                                                        </DataTrigger>

                                                        <DataTrigger Binding="{Binding Sezione}" Value="4">
                                                            <Setter Property="ContentControl.ContentTemplate" Value="{StaticResource ResourceKey=SezioneEsagono}"/>
                                                        </DataTrigger>

                                                    </Style.Triggers>
                                                </Style>
                                            </ContentControl.Style>
                                        </ContentControl>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                            <GridViewColumn Header="mm/pz" Width="50">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBox Text="{Binding Lunghezza}" ab:AttachedProperties.AutoSelectText="True"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>

                            <GridViewColumn Header="€/pz" DisplayMemberBinding="{Binding PrezzoUnitario,StringFormat={}{0:C}}" Width="70"/>

                            <GridViewColumn Header="Kg" DisplayMemberBinding="{Binding PesoUnitario, StringFormat=F3}" Width="70" />

                            <GridViewColumn>
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate>
                                        <Button Content="Del" Command="{Binding DataContext.DelMaterialDetailCmd, RelativeSource={RelativeSource AncestorLevel=1, AncestorType={x:Type Window}, Mode=FindAncestor}}"
                                                CommandParameter="{Binding}"/>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>
            </StackPanel>
        </Border>
        <StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Right" Grid.ColumnSpan="2" >
            <Button Content="Cancel" Width="100" Margin="5" Click="Button_Click_1" />
            <Button Content="Ok" Width="100" Margin="5" Click="Button_Click" />
        </StackPanel>
    </Grid>
</Window>
